/**
 * 轨迹回放工具类
 */

var TrackMap = {
	init: function(){
		var map = new AMap.Map("container", {
	        resizeEnable: true,
	        center: [113.26006, 23.13399],//[116.397428, 39.90923],
	        zoom: 13
	    });
	},
	initEvent: function(){
	   
	},
	initMap: function(carPic,lineArr){
		var map = new AMap.Map("container", {
	        resizeEnable: true,
	        center: lineArr[0],
	        zoom: 17
	    });
	    marker = new AMap.Marker({
	        map: map,
	        position: lineArr[0],
	        icon: carPic,//"http://webapi.amap.com/images/car.png",
	        offset: new AMap.Pixel(-26, -13),
	        autoRotation: true
	    });
	    
	    startMarker = new AMap.Marker({
	        map: map,
	        position: lineArr[0],
	        icon: global.url.domain + "gps-web/resources/images/mapTool/start.png",
	        offset: new AMap.Pixel(-15, -30)
	    });
	    
	    endMarker = new AMap.Marker({
	        map: map,
	        position: lineArr[lineArr.length-1],
	        icon: global.url.domain + "gps-web/resources/images/mapTool/end.png",
	        offset: new AMap.Pixel(-15, -30)
	    });
	    

	   
	    // 绘制轨迹
	    var polyline = new AMap.Polyline({
	        map: map,
	        path: lineArr,
	        strokeColor: "#00A",  //线颜色
	        // strokeOpacity: 1,     //线透明度
	        strokeWeight: 3,      //线宽
	        // strokeStyle: "solid"  //线样式
	    });
	    var passedPolyline = new AMap.Polyline({
	        map: map,
	        // path: lineArr,
	        strokeColor: "#F00",  //线颜色
	        // strokeOpacity: 1,     //线透明度
	        strokeWeight: 3,      //线宽
	        // strokeStyle: "solid"  //线样式
	    });
	    
	    marker.on('moving',function(e){
	        passedPolyline.setPath(e.passedPath);
	    })
	    map.setFitView();

	    AMap.event.addDomListener(document.getElementById('start'), 'click', function() {
	        marker.moveAlong(lineArr, 500);
	    }, false);
	     AMap.event.addDomListener(document.getElementById('pause'), 'click', function() {
	        marker.pauseMove();
	       }, false);
	      AMap.event.addDomListener(document.getElementById('resume'), 'click', function() {
	        marker.resumeMove();
	    }, false);
	    AMap.event.addDomListener(document.getElementById('stop'), 'click', function() {
	        marker.stopMove();
	    }, false);
	},
	initMapNoMarker: function(carPic,lineArr){
		var map = new AMap.Map("container", {
	        resizeEnable: true,
	        center: lineArr[0],
	        zoom: 17
	    });

	    
	    startMarker = new AMap.Marker({
	        map: map,
	        position: lineArr[0],
	        icon: global.url.domain + "gps-web/resources/images/mapTool/start.png",
	        offset: new AMap.Pixel(-15, -30)
	    });
	    
	    endMarker = new AMap.Marker({
	        map: map,
	        position: lineArr[lineArr.length-1],
	        icon: global.url.domain + "gps-web/resources/images/mapTool/end.png",
	        offset: new AMap.Pixel(-15, -30)
	    });
	    

	   
	    // 绘制轨迹
	    var polyline = new AMap.Polyline({
	        map: map,
	        path: lineArr,
	        strokeColor: "#00A",  //线颜色
	        // strokeOpacity: 1,     //线透明度
	        strokeWeight: 3,      //线宽
	        // strokeStyle: "solid"  //线样式
	    });
	    var passedPolyline = new AMap.Polyline({
	        map: map,
	        // path: lineArr,
	        strokeColor: "#F00",  //线颜色
	        // strokeOpacity: 1,     //线透明度
	        strokeWeight: 3,      //线宽
	        // strokeStyle: "solid"  //线样式
	    });
	    

	    map.setFitView();

	    AMap.event.addDomListener(document.getElementById('start'), 'click', function() {
	        marker.moveAlong(lineArr, 500);
	    }, false);
	     AMap.event.addDomListener(document.getElementById('pause'), 'click', function() {
	        marker.pauseMove();
	       }, false);
	      AMap.event.addDomListener(document.getElementById('resume'), 'click', function() {
	        marker.resumeMove();
	    }, false);
	    AMap.event.addDomListener(document.getElementById('stop'), 'click', function() {
	        marker.stopMove();
	    }, false);
	}
};